package com.axon.base.managers
{
	import com.axon.base.interfaces.IAxSetInitialFocus;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	
	import mx.controls.Alert;
	import mx.core.IFlexDisplayObject;
	import mx.core.UIComponent;
	import mx.managers.PopUpManager;
	
	public class AxPopUpManager
	{
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public function AxPopUpManager() 
		{
			super();
		}
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public static function messageDlg (	text				: String	= "", 
											title				: String	= "",
                               				flags				: uint		= 0x4 /* Alert.OK */, 
                               				parent				: Sprite	= null, 
                               				closeHandler		: Function	= null, 
                               				iconClass			: Class		= null, 
                               				defaultButtonFlag	: uint		= 0x4 /* Alert.OK */ ): Alert
		{
		   	return Alert.show(text, title, flags, parent, closeHandler, iconClass, defaultButtonFlag);
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public static function createPopUp(	parent			: DisplayObject, 
											ComponentClass	: Class, 
											modal			: Boolean 		= false, 
											childList		: String 		= null ): IFlexDisplayObject 
		{
			var window: IFlexDisplayObject = PopUpManager.createPopUp(parent, ComponentClass, modal, childList) as IFlexDisplayObject;

			centerPopUp(window);
			
			if ( window is UIComponent )
   				(window as UIComponent).setFocus();
   			
   			if ( (window is IAxSetInitialFocus) && (IAxSetInitialFocus(window).initialFocusControl) )
   				IAxSetInitialFocus(window).initialFocusControl.setFocus();
   				
   			return window;
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public static function closePopUpWindow(window: IFlexDisplayObject): void
		{
			PopUpManager.removePopUp(window);
		}
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public static function centerPopUp(popUp: IFlexDisplayObject): void 
		{
			popUp.x = (popUp.parent.width  - popUp.width) / 2;
			popUp.y = (popUp.parent.height - popUp.height) / 2;
			PopUpManager.centerPopUp(popUp);
			popUp.y = popUp.y - 40;	
		}
		
	}
}